<?php

if($_GET['_a']=='d')
{
	$id = $_GET['_d'];
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
		
 $id = $_REQUEST['_d'];
		mysql_query("delete from contact where id='$id'");
	
	//header("location:index.php?tc=picture&_st=$st&page=$page&_s=2");
	echo "<script>window.location='index.php?tc=contact&_st=$st&page=$page&_s=2'</script>";
	exit;
}

?>
<form name="nnf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Users</span></td>
	<td width="40%" align="right" class="font12">
    </td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="2" height="11"></td>
</tr>    
</table>
</form>
	<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if($_REQUEST['_sus'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg">
        <img src="images/information.png" align="absmiddle" />&nbsp;Mail Send  Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr class="font12">
    <td align="center" width="30">#</td>
    <td align="center" width="50">Name</td>
    <td align="center" width="50">Company</td>
    <td align="center" width="150">Address </td>
    <td align="center" width="150">City</td>
    <td align="center" width="164">State</td>
    <td align="center" width="164">Country</td>
 
    <td align="center" width="164">Contact</td>

    <td align="center" width="150">Comments</td>
    <td align="center" width="240">Status</td>
    <td width="50" align="center">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=contact&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];
if($st == "" || $st == 2)
{
	$res = mysql_query("select id from contact");
}

$query = mysql_query("select * from contact order by id desc limit $offset , $rowsPerPage");
$i = 1;
while($q = mysql_fetch_array($query))
{ 
	if($q["mail_status"] == 1) $status = "<img src='images/replied.png'>";
	else $status = "<img src='images/no_reply.png'>";
	?>
    <tr class="font12">
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left"><?php echo stripslashes(substr($q["name"],0,30));?>...</td>
        <td align="left"><?php echo stripslashes(substr($q["company"],0,10));?>...</td>
        <td align="left"><?php  echo stripslashes(substr($q['street_address'],0,10));?>...</td>
        <td align="left"><?php echo stripslashes(substr($q['city'],0,10));?>...</td>
        <td align="left"><?php  echo stripslashes(substr($q['state'],0,10));?>...</td>
        <td align="left"><?php  echo stripslashes(substr($q['country'],0,10));?>...</td>
        
        <td align="left"><?php echo stripslashes(substr($q['phone'],0,10));?>...</td>
       
        <td align="left"><?php echo stripslashes(substr($q['comments'],0,30));?></td>
        <td align="center">
       
        <a class="font12" href="index.php?tc=contact_view&_d=<?php echo $q['id'];?>&page=<?php echo $pageNum;?>">View</a> | 
        	<a  class="font12"href="index.php?tc=contact&_d=<?php echo $q['id'];?>&_a=d&page=<?php echo $pageNum;?>" onclick="return confirm('Are you sure want to delete?')">Delete</a>
        </td>
        <td align="center"><?php echo $status;?></td>
   	</tr>     
<?php 
	$i++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="13" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>   